<?php
if(!defined('IN_SITE')) exit('Access Denied');
switch($do)
{
    case "":
        require_once('include/page.inc.php');
        //管理员头像
       	if($_SESSION["___isadmin"]) {
        	$isAdmin = 1;
        	$adminInfo= $db->SelectS("select * from systemuser where id=".$_SESSION["___isadmin"],1);
        }
        else {
        	$isAdmin = 0;
        	$adminInfo= $db->SelectS("select * from systemuser",1);
        }
        $adminInfo['headpic'] = $adminInfo['headpic'] ? $adminInfo['headpic'] : 'upload/headicons/1.jpg';
        $face = $_SESSION["___isadmin"] ? $adminInfo['headpic'] : 'upload/headicons/1.jpg';
        
        $where = "fid=0 and poster=0";
        /*if(!$_SESSION["___isadmin"]) {
            $where.=" and ispower=0";  //ispower:是否只针对管理员
        }*/
        $pageNum = $_GET['page'];
        $page = new Page(array(
			'table'=>"message",
			'pagesize'=>$CONFIGURE["pagesize"],
			'page'=>$pageNum,
			'key'=>'id',
			'where'=>$where,
			'page_record'=>"条留言"
         ));
        $pagelist = $page->pages();
        if(is_array($pagelist))
        {
            $_pagelist = array();
            foreach($pagelist as $_p) {
				$comments = $db->SelectS("select * from message where fid=".$_p["id"]." ORDER BY id DESC");
				if ($_SESSION["___isadmin"]) {
					if(is_array($comments) && count($comments)>0) {
						$_p["replay"] = '<div class="reply_container"><ul class="feedback">';
						foreach($comments as $commentKey=>$comment) {
		                    $_p["replay"] .='<li';
			              	if($commentKey+1 == count($comments)) {
			                   	 $_p["replay"] .= ' class="noborder" ';
							}
		                    $_p["replay"] .= ' id="mess_'.$comment['id'].'"><div class="head_box2"><div class="head_pic"><img class="adminHead" src="'.$adminInfo['headpic'].'" alt="'.$comment['nickname'].'" width="48" height="48"/></div><div class="user_name">管理员</div></div>
		                        <div class="feeds_content"><p>'.stripslashes($comment["content"]).'</p><div class="record">';
							if($_SESSION["___isadmin"]){
								$_p["replay"] .= '<a href="javascript:void(0);" onClick="delComment('.$comment['id'].');" class="right">删除</a>';
							}
							$_p["replay"] .= date("Y-m-d H:i",$comment["createtime"]);
							if($_SESSION["___isadmin"]){
								$_p["replay"] .= '<em>|</em>IP:'.$comment["ip"];
							}	
							$_p["replay"] .= '</div></div><div class="clear"></div></li>';
						}
					}
					else {
						$_p["replay"] = '<div class="reply_container" style="display:none;"><ul class="feedback">';
					}
	            	$_p["replay"] .= '<li class="noborder" id="comment_box_'.$_p['id'].'" style="display:none;" ><div class="comment"><a class="closed_3" href="javascript:void(0);" onclick="hideCommentBox('.$_p['id'].');">close</a><div class="comment_text"><textarea rows="" name="" cols="" class="textarea_380" id="commentArea_'.$_p['id'].'"></textarea><!--<a href="javascript:void(0);" class="faces left" onclick="showFace(this,\'commentArea_'.$_p['id'].'\',-12,30)">表情</a>--><div class="right"><a href="javascript:void(0);" class="btn" onclick="comment('.$_p['id'].')"><span>发 布</span></a></div></div><div class="clear"></div></div></li>';
	            	$_p["replay"] .= '</ul><div class="comm_btm"></div></div>';
				}
				else {
					if(is_array($comments) && count($comments)>0) {
						$_p["replay"] = '<div class="reply_container"><ul class="feedback">';
						foreach($comments as $commentKey=>$comment) {
		                    $_p["replay"] .='<li';
			              	if($commentKey+1 == count($comments)) {
			                   	 $_p["replay"] .= ' class="noborder" ';
							}
		                    $_p["replay"] .= ' id="mess_'.$comment['id'].'"><div class="head_box2"><div class="head_pic"><img src="'.$adminInfo['headpic'].'" alt="'.$comment['nickname'].'" width="48" height="48"/></div><div class="user_name">管理员</div></div>
		                        <div class="feeds_content"><p>'.stripslashes($comment["content"]).'</p><div class="record">';
							$_p["replay"] .= date("Y-m-d H:i",$comment["createtime"]);
							$_p["replay"] .= '</div></div><div class="clear"></div></li>';
						}
						$_p["replay"] .= '</ul><div class="comm_btm"></div></div>';
					}
					else {
						$_p["replay"] = '';
					}
				}
	            //关键字过滤
		        if(is_array($CONFIGURE["filter"])) {
		            foreach($CONFIGURE["filter"] as $o) {
		                $_p["content"] = str_ireplace($o,"*",$_p["content"]);
		                $_p["nickname"] = str_ireplace($o,"*",$_p["nickname"]);
		            }
		        }
				$_p["content"] = str_ireplace(array("<br>", "<br/>", "<br />"), "</p><p>", $_p["content"]);
				$_pagelist[]=$_p;
            }
        }
        $pagestr = $page->SetPageStr();
        
        $where = "fid=0 and poster!=0 and IFNULL(istop,0)!=1"; 
        $board = new Page(array(
        	'table'=>"message",
			'pagesize'=>$CONFIGURE["board_pagesize"],
			'page'=>1,
			'key'=>'id',
			'where'=>$where,
        	//'condition' => ' ORDER BY istop DESC,id DESC' 
		));
		$_boardlist = array();
  		$boardlist = $board->pages();
  		if(is_array($boardlist)){
            foreach($boardlist as $_b) {
            	//关键字过滤
		        if(is_array($CONFIGURE["filter"])) {
		            foreach($CONFIGURE["filter"] as $o) {
		                $_b["content"] = str_ireplace($o,"*",$_b["content"]);
		                $_b["nickname"] = str_ireplace($o,"*",$_b["nickname"]);
		            }
		        }
		        $_b["content"] = str_ireplace(array("<br>", "<br/>", "<br />"), "</p><p>", stripslashes($_b["content"]));
		        $_boardlist[] = $_b;
            }
        } 
  		$sqlTop = "select * from message where fid=0 and poster!=0 and istop=1"; 
  		$boardTop = $db->SelectS($sqlTop,1);
  		if($boardTop) {
  			$boardTop["content"] = str_ireplace(array("<br>", "<br/>", "<br />"), "</p><p>", $boardTop["content"]);
  			array_unshift($_boardlist,$boardTop);
  		}
  		//表情
        $faces = include(FILE_ROOT.'include/face.inc.php');
        //头像
        $heads = getFilesInDir(FILE_ROOT.'upload/headicons');
		foreach($heads as $head) {
			$headIcons[] = "upload/headicons/".$head;
		}
		//版权信息
		$copyright = base64_decode('0tfTzsH00dSw5VYxLjAmbmJzcDsmY29weTsyMDEwILr+sbHKoszszfjC57y8yvXT0M/euavLviDL+dPQyKjA+7GjwfQ8YSB0YXJnZXQ9Il9ibGFuayIgaHJlZj0iaHR0cDovL3d3dy5zdG50cy5jb20iPtLX08652be9zfjVvjwvYT58PGEgdGFyZ2V0PSJfYmxhbmsiIGhyZWY9Imh0dHA6Ly9iYnMuc3RudHMuY29tIj652be9wtvMszwvYT4=');
		include template("index");
   	break;
    case "login":
		include(template("pass"));
        break;
    case "edit":
		if($_SESSION["___iswrite"]=="" || $_SESSION["___iswrite"]!=$aid) {
			exit("<script language='javascript'>history.back();</script>");
		}
		else {
			include(template("edit"));
		}
    break;
    case "delete":
        if($aid>0)
        {
            $db->table="message";
            $db->Delete("id",$aid);
            $db->Delete("fid",$aid);
            msg("删除成功","?act=index");
        }
        break;
    default:
        exit("<script language='javascript'>history.back();</script>");
    break;
}


?>